package com.aode.music.adapter.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.aode.common.bean.response.Mllist;
import com.aode.common.bean.response.Music;
import com.aode.music.R;
import com.aode.music.databinding.ItemHomePlaylistBinding;

import java.util.ArrayList;

public class HomePlayListAdapter extends RecyclerView.Adapter {
    private Context context;
    private ArrayList<Mllist> mllistArrayList;
    private PlayListInterface playListInterface;
    public HomePlayListAdapter(Context context, ArrayList<Mllist> mllistArrayList,PlayListInterface playListInterface){
        this.context = context;
        this.mllistArrayList = mllistArrayList;
        this.playListInterface =  playListInterface;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemHomePlaylistBinding playlistBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_home_playlist,parent,false);
        return new HomePlayListHolder(playlistBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        HomePlayListHolder playListHolder = (HomePlayListHolder) holder;
        if(mllistArrayList.size()>0&&!mllistArrayList.isEmpty()){
            Mllist mllist = mllistArrayList.get(position);
            playListHolder.getPlaylistBinding().setMllist(mllist);
            playListHolder.getPlaylistBinding().setPlaylistinterface(playListInterface);
        }

    }

    @Override
    public int getItemCount() {
        return mllistArrayList.size();
    }

    class HomePlayListHolder extends RecyclerView.ViewHolder{
        private ItemHomePlaylistBinding  playlistBinding;
        public HomePlayListHolder(ItemHomePlaylistBinding  playlistBinding) {
            super(playlistBinding.getRoot());
            this.playlistBinding = playlistBinding;
        }

        public ItemHomePlaylistBinding getPlaylistBinding() {
            return playlistBinding;
        }

        public void setPlaylistBinding(ItemHomePlaylistBinding playlistBinding) {
            this.playlistBinding = playlistBinding;
        }
    }

    public interface PlayListInterface{
        void onItemClick(Mllist mllist);
    }
}
